from itsdangerous import TimedJSONWebSignatureSerializer  as Serializer, BadSignature
from requests import Response
from rest_framework import status

from mall.settings import SECRET_KEY
from users.models import User


def generate_verify_email_url(id,email):
# 加密用户信息
    s=Serializer(secret_key=SECRET_KEY,expires_in=300)
    data1={
        'id':id,
        'email':email
    }
    token=s.dumps(data1)
# 拼接verify_url,网址?token=xxx
    verify_url = 'http://www.meiduo.site:8080/success_verify_email.html?token=' + token.decode()
    return verify_url

def check_userid(token):
    s=Serializer(secret_key=SECRET_KEY,expires_in=300)
    # 解密出来是一个对象
    try:
        dict=s.loads(token)
    except BadSignature:
        return None
    return dict

